// pages/circle/circle.js
const mixins = require('../../../mixins/forum')
const common = require('../../../mixins/common')
const app = getApp()
import deviceUtil from "../../../linui/utils/device-util";
import config from "../../../api/config";
let interstitialAd = null;

const options = {
  /**
   * 页面的初始数据
   */
  data: {
    tabbar: config.tarbar,
    advert: app.globalData.advert,
    isIphoneX: app.globalData.isIphoneX,
    cats: [],
    subcats: [],
    curIndex: 0,
    interstitialAd: config.interstitialAd,
    page: 1,
    taga: [
      {
      text: "小组",
      id: 0
    },
    {
      text: "|",
    
    },
     {
      text: "关注",
      id: 1
    }],
    page: 1,
    mypages: 1,
    currentItem: 0,
    subcatsloading: true,
    isLastmyPage: false,
    currentConfig: {
      show: false,
      transition: true,
      zIndex: 99,
      locked: false,
      direction: 'bottom',
      arcRadius: 18,
      maxHeight: 600,
      minHeight: 600,
      opacity: 0.4
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (wx.createInterstitialAd && this.data.advert.interstitialAd) {
      interstitialAd = wx.createInterstitialAd({
        adUnitId: this.data.advert.interstitialAd
      })
      interstitialAd.onLoad(() => {})
      interstitialAd.onError((err) => {})
      interstitialAd.onClose(() => {})
    }
    this.getCircleLists({
      parent: 0,
      per_page: 100,
    });
    this.getSiteInfos();
  },


  gotosearch: function () {
    wx.navigateTo({
      url: '/pages/search/search',
    })
  },

  switchRightTab: function (t) {
    var e = t.target.dataset.id,
      a = parseInt(t.target.dataset.index);
    this.setData({
      subcatsloading: true,
      curNav: e,
      curIndex: a,
      scrollTop: 0,
      page: 1,
      parent: e,
      subcats: [],
    });
    if (this.data.subcatsloading) {
      this.getSubCieclelist({
        parent: e
      })
    }
  },
  select: function (t) {
    var e = this;
    e.setData({
      currentItem: t.target.dataset.id,
      focus: !1
    })
    if (this.data.currentItem == 1) {
      if (interstitialAd) {
        interstitialAd.show().catch((err) => {
          console.error(err)
        })
      }
      this.getCircleByMine();
    }
  },

  addNewCircle: function () {
    wx.navigateTo({
      url: '/pages/circle/creat',
    })
  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    "function" == typeof this.getTabBar && this.getTabBar() && this.getTabBar().setData({
      selected: 1
    })

    let user = app.globalData.user
    if (!user) {
      user = '';
    }
    this.setData({
      user: user,
    })

  },

  loadmore: function (e) {
    this.setData({
      isBottom: true,
    })
    if (!this.data.isLastPage&&!this.data.subcatsloading) {
      this.getSubCieclelist({
        parent: this.data.parent,
        page: this.data.page
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  loadMoreCircle: function () {
    console.log(1);
    this.setData({
      isBottoms: true,
    })
    if (!this.data.isLastmyPage && this.data.currentItem == 1) {
      this.getCircleByMine({
        page: this.data.mypages
      })
    }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    return {
      title: this.data.title + '__圈子列表',
      path: '/pages/tabbar/circle/circle',
      imageUrl: this.data.cover,
      success: (res) => {
        console.log("转发成功", res);
      },
      fail: (res) => {
        console.log("转发失败", res);
      }
    }
  },
  onShareTimeline: function (res) {
    return {
      title: this.data.title + '__圈子列表',
      query: '',
      imageUrl: this.data.cover //图片地址
    }
  }


}

mixins(options)
common(options)
Page(options)